package com.mcz.yun4book.dao.impl;

import com.mcz.yun4book.dao.mapper.BookMapper;
import com.mcz.yun4book.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public abstract class BookDaoJdbcImpl implements BookMapper {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<Book> findAll(Book book) {

        return jdbcTemplate.query("select * from t_book", new RowMapper<Book>() {
            @Override
            public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
                Book book=new Book();
                book.setId(rs.getInt("id"));
                book.setImg(rs.getString("img"));
                book.setName(rs.getString("name"));
                book.setPrice(rs.getDouble("price"));
                book.setDescri(rs.getString("descri"));
                book.setAuthor(rs.getString("author"));
                book.setPub(rs.getString("pub"));
                book.setPubDate(rs.getDate("pub_date"));
                return book;
            }
        });
    }

    }
